<template>
  <div class="app-container pb-[70px]">
    <el-form ref="queryFormRef" v-hasPerm="['parameter/options']" :model="formData" :inline="true" label-width="310px">
      <div class="search-container">
        <el-row :gutter="10">
          <el-col :lg="24" :xs="24">
            <div class="title !mb-[10px]">系统配置</div>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="对公账户名称" prop="account_name">
              <el-input v-model="formData.parameter.account_name" placeholder="输入对公账户名称" clearable />
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="对公账户号码" prop="account_number">
              <el-input v-model="formData.parameter.account_number" placeholder="输入对公账户号码" clearable />
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="对公账户银行" prop="account_bank">
              <el-input v-model="formData.parameter.account_bank" placeholder="输入对公账户银行" clearable />
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员人脉圈发布建立扣除金额" prop="network_circle_add_price">
              <el-input type="number" v-model.number="formData.parameter.network_circle_add_price"
                placeholder="输入非会员人脉圈发布建立扣除金额" clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员人脉圈发布扣除邀新人次数" prop="network_circle_add_invitation">
              <el-input type="number" v-model.number="formData.parameter.network_circle_add_invitation"
                placeholder="输入非会员人脉圈发布扣除邀新人次数" clearable>
                <template #append>次</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员人脉圈查看关键信息扣除金额" prop="network_circle_show_price">
              <el-input type="number" v-model.number="formData.parameter.network_circle_show_price"
                placeholder="输入非会员人脉圈查看关键信息扣除金额" clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员人脉圈查看关键信息扣除邀新次数" prop="network_circle_show_invitation">
              <el-input type="number" v-model.number="formData.parameter.network_circle_show_invitation"
                placeholder="输入非会员人脉圈查看关键信息扣除邀新次数" clearable>
                <template #append>次</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员项目库合伙人发布扣除金额" prop="project_add_price">
              <el-input type="number" v-model.number="formData.parameter.project_add_price"
                placeholder="输入非会员项目库合伙人发布扣除金额" clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员项目库合伙人发布扣除邀新人次数" prop="project_add_invitation">
              <el-input type="number" v-model.number="formData.parameter.project_add_invitation"
                placeholder="输入非会员项目库合伙人发布扣除邀新人次数" clearable>
                <template #append>次</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员项目库合伙人查看关键信息扣除金额" prop="project_show_price">
              <el-input type="number" v-model.number="formData.parameter.project_show_price"
                placeholder="输入非会员项目库合伙人查看关键信息扣除金额" clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="非会员项目库合伙人查看关键信息扣除邀新次数" prop="project_show_invitation">
              <el-input type="number" v-model.number="formData.parameter.project_show_invitation"
                placeholder="输入非会员项目库合伙人查看关键信息扣除邀新次数" clearable>
                <template #append>次</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="会员返佣点数" prop="vip_commission_rate">
              <el-input type="number" v-model.number="formData.parameter.vip_commission_rate"
                placeholder="输入会员返佣点数 1-100" max="100" min="1" clearable>
                <template #append>%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="会员终身定价" prop="vip_price">
              <el-input type="number" v-model.number="formData.parameter.vip_price" placeholder="输入会员终身定价" clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="会员年费定价" prop="vip_year_price">
              <el-input type="number" v-model.number="formData.parameter.vip_year_price" placeholder="输入会员年费定价"
                clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="会员一年赠送天数" prop="vip_year_give">
              <el-input type="number" v-model.number="formData.parameter.vip_year_give" placeholder="输入会员一年赠送天数"
                clearable>
                <template #append>天</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="会员一月定价" prop="vip_month_price">
              <el-input type="number" v-model.number="formData.parameter.vip_month_price" placeholder="输入会员一月定价"
                clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="会员一月赠送天数" prop="vip_month_give">
              <el-input type="number" v-model.number="formData.parameter.vip_month_give" placeholder="输入会员一月赠送天数"
                clearable>
                <template #append>天</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="微信支付商户号id" prop="wx_mchid">
              <el-input v-model="formData.parameter.wx_mchid" placeholder="输入微信支付商户号id" clearable />
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="微信支付appid" prop="app_id">
              <el-input v-model="formData.parameter.app_id" placeholder="输入微信支付appid" clearable />
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="佣金提取限制" prop="commission_rule">
              <el-input type="number" v-model.number="formData.parameter.commission_rule" placeholder="输入佣金提取限制"
                clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="收益提取限制" prop="profit_proportion_rule">
              <el-input type="number" v-model.number="formData.parameter.profit_proportion_rule" placeholder="输入收益提取限制"
                clearable>
                <template #append>元</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="开启收益" prop="is_profit">
              <el-switch v-model="formData.parameter.is_profit" :active-value="1" :inactive-value="0" active-text="开启"
                inactive-text="关闭" />
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="收益比例" prop="profit_proportion">
              <el-input type="number" v-model.number="formData.parameter.profit_proportion" placeholder="输入收益提取限制"
                clearable>
                <template #append>%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="开启截图功能" prop="upload_rule">
              <el-switch v-model="formData.parameter.upload_rule" :active-value="0" :inactive-value="1" active-text="开启"
                inactive-text="关闭" />
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <div class="search-container">
        <el-row :gutter="10">
          <el-col :span="24">
            <div class="title !mb-[10px]">小程序相关配置</div>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="附图" prop="images">
              <image-upload :limit="1" v-model="formData.app.images" />
            </el-form-item>
          </el-col>
          <el-col :lg="12" :xs="24">
            <el-form-item class="!w-[95%]" label="banner图片" prop="banners">
              <image-upload :limit="9" v-model="formData.app.banners" />
            </el-form-item>
          </el-col>

          <el-col :lg="24" :xs="24">
            <el-form-item class="!w-[95%]" label="公司描述" prop="brief_introduction">
              <editor v-model="formData.app.brief_introduction" style="height: calc(100vh - 300px)" />
            </el-form-item>
          </el-col>

          <el-col :lg="24" :xs="24">
            <el-form-item class="!w-[95%]" label="其他" prop="other">
              <editor v-model="formData.app.other" style="height: calc(100vh - 300px)" />
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>

    <div class="fixed bottom-0 left-0 bg-white !w-[100%]">
      <div class="flex justify-center items-center h-[60px]">
        <el-button v-hasPerm="['parameter/set']" type="primary" @click="handleSubmit">保存</el-button>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
defineOptions({
  name: "Basic",
  inheritAttrs: false,
});
import BasicAPI from "@/api/basic";
import Editor from "@/components/WangEditor/index.vue";
import ImageUpload from "@/components/Upload/ImageUpload.vue";
import { number } from "echarts";

const formData = ref({
  app: {
    brief_introduction: '',
    other: '',
    image: '',
    banner: '',
    images: [],
    banners: []
  },
  parameter: {} as any
})

const handleSubmit = () => {
  if (formData.value.app.images.length > 0) {
    formData.value.app.image = formData.value.app.images.join(",") as any;
  }
  if (formData.value.app.banners.length > 0) {
    formData.value.app.banner = formData.value.app.banners.join(",") as any;
  }

  BasicAPI.getInfoSet(formData.value).then((res: any) => {
    ElMessage.success("操作成功");
    hanldePageInfo();
  })
}

// 获取详情
const hanldePageInfo = () => {
  BasicAPI.getPageInfo().then((res: any) => {
    if (res.app.image != "") {
      res.app.images = res.app.image.split(",");
    } else {
      res.app.images = [];
    }

    if (res.app.banner != "") {
      res.app.banners = res.app.banner.split(",");
    } else {
      res.app.banners = [];
    }
    formData.value = res;
  })
}

onMounted(() => {
  hanldePageInfo();
})
</script>
